package de.java.swing.extension.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

import de.java.swing.extension.utils.ToolbarConstants;

/**
 * TODO Kommentar.
 * 
 * @author Patrick Haas
 * @since 1.0.0
 * 
 */
public class ToolbarItem extends ExtendedPanel implements ToolbarConstants {

	private static final long serialVersionUID = 8266856704623924798L;

	private ExtendedPanel centerPane;

	private JLabel textLabel;

	private Color mouseOverColor = DEFAULT_MOUSE_OVER_COLOR;

	private Color mouseOutColor = DEFAULT_MOUSE_OUT_COLOR;

	private ToolbarItem() {
		initialize();
	}

	public ToolbarItem(ImageIcon icon) {
		this();
		this.textLabel.setIcon(icon);
	}

	public ToolbarItem(String text, ImageIcon icon) {
		this();
		this.textLabel.setText(text);
		this.textLabel.setIcon(icon);
	}

	public void setMouseOverColor(Color c) {
		mouseOverColor = c;
	}

	public Color getMouseOverColor() {
		return mouseOverColor;
	}

	public void setMouseOutColor(Color c) {
		mouseOutColor = c;
		this.textLabel.setForeground(c);
	}

	public Color getMouseOutColor() {
		return mouseOutColor;
	}

	public void setImage(ExtendedImage image) {
		this.textLabel.setIcon(new ImageIcon(image.getImage()));
	}

	private void initialize() {
		this.setLayout(new BorderLayout());
		this.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent e) {
				textLabel.setForeground(mouseOverColor);
				textLabel.repaint();
				repaint();
			}

			@Override
			public void mouseExited(MouseEvent e) {
				textLabel.setForeground(mouseOutColor);
				textLabel.repaint();
				repaint();
			}
		});

		centerPane = new ExtendedPanel();
		centerPane.setLayout(new BorderLayout());
		this.add(BorderLayout.CENTER, centerPane);

		textLabel = new JLabel();
		textLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		textLabel.setBackground(new Color(0, 0, 0, 0));
		textLabel.setForeground(mouseOutColor);
		centerPane.add(textLabel);

	}
}
